package com.example.tsbs.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tsbs.entity.MZ;
import com.example.tsbs.entity.Task;
import com.example.tsbs.mapper.SystemInfoMapper;
import com.example.tsbs.service.TaskService;
import com.example.tsbs.mapper.TaskMapper;
import com.example.tsbs.util.FileUtil;
import com.example.tsbs.util.UseUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* @author jiang
* @description 针对表【task】的数据库操作Service实现
* @createDate 2024-03-06 15:10:17
*/
@Slf4j
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task>
    implements TaskService{

    @Autowired
    private TaskMapper taskMapper;

    @Autowired
    private SystemInfoMapper systemInfoMapper;

    @Override
    public PageInfo<Task> get(int pageNumber, int pageSize, Integer taskName, String taskType) {
        PageHelper.startPage(pageNumber, pageSize);
        return new PageInfo<>(taskMapper.get(taskName,taskType));
    }

    /**
     *  任务计算
     * @param id   result_path、inp_path:"/root/xxx",xxx为目录
     * @return
     */
    @SneakyThrows
    @Override
    public String getStorage(Integer id) {
        String res = "";
        Task task = taskMapper.getById(id);
        Task endTask = taskMapper.getById(id);
        endTask.setProgress(1.0);
        endTask.setDone(1);
        //设置初始任务进度
        final double[] progress = {0.0};
        task.setProgress(0.01);
        taskMapper.updating(task, task.getId());
        log.info("parameter参数:"+JSON.parseObject(task.getParameter()).toString());

//        try {


            String containerId = "";
            String containerName = "";
            if (ObjectUtils.isEmpty(systemInfoMapper.getById(1))) {
//                res = "数据库表格中未找到容器信息";
//                task.setProgress(1.0);
//                task.setResponse("{\"log\":" + "\"" + res + "\"}");
//                taskMapper.updating(task, task.getId());
//                return res;
                containerName = "ubuntu2";
            } else {
                containerId = systemInfoMapper.getById(1).getDockerId();
                containerName = systemInfoMapper.getById(1).getDockerName();
            }
//            log.info("docker容器id:" + containerId + "docker容器名称" + containerName);
        log.info("podman容器id:" + containerId + "podman容器名称" + containerName);


            //生成MZ、CZ、BP、BS可执行程序用到的json文件
            log.info(task.getType()+"准备生成可执行程序用到的.json文件");
            res = UseUtil.paramToJsonFile(task, containerId, containerName);
            //生成json更新任务进度0.05
            if (!res.equals("成功")) {
                //更新任务进度
                task.setProgress(1.0);
                task.setResponse("{\"log\":" + "\"" + res + "\"}");
                task.setDone(1);
                taskMapper.updating(task, task.getId());
                log.info("返回结果：" + res);
                return res;
            } else {
                task.setProgress(0.05);
                taskMapper.updating(task, task.getId());
            }


            //生成gltf文件      CAD、PAR、CZ的inp文件暂固定
            log.info(task.getType()+"准备生成gltf文件");
            if (Objects.equals(task.getType(), "BP") || Objects.equals(task.getType(), "bp")) {
                log.info("板块元频域任务BP，调用guapi_mesh.py，参数生成gltf");
                //板块元频域任务BP
                JSONObject json = JSON.parseObject(task.getParameter());
                //调用频域的py程序,获取.gltf网格文件，并将结果文件复制到指定文件夹  频域、时域共用一个py程序
                //python3 /root/tsbsDuiJie/ts/guapi_mesh.py [0, 360, 1] [60, 120, 1] 50.0 [31.0, 0.0, 0.0] [0.0, 1.0, 0.0] [-1.0, 0.0, 0.0] guapi.gltf
                String result2 = UseUtil.callBPPythonAndCopy("/root/tsbsDuiJie/ts/guapi_mesh.py", task.getParameter(), containerName);
                res = result2;
            }
            else if (Objects.equals(task.getType(), "BS") || Objects.equals(task.getType(), "bs")) {
                log.info("板块元时域任务BS，调用light_inp_to_gltf.py，用inp生成gltf");
                //板块元时域任务BS
                JSONObject json = JSON.parseObject(task.getParameter());
                //调用时域的light_inp_to_gltf.py程序,获取gltf网格文件，并将结果文件复制到指定文件夹  频域、时域共用一个py程序
                //python3 ./time_light/light_inp_to_gltf.py  ./mesh20240401.inp light.gltf True
                String result3 = UseUtil.callBSPythonAndCopy("/root/tsbsDuiJie/time_light/light_inp_to_gltf.py", task.getParameter(), "True", containerName);
                res = result3;
            }
            else if (Objects.equals(task.getType(), "CZ") || Objects.equals(task.getType(), "cz")) {
                //CZ-material生成csv和dat文件在生成dat集合中
                JSONObject json = JSON.parseObject(task.getParameter());
                try {
                    String type = json.getString("type");
                    //CZ-cad调用可执行程序mkmesh，生成inp文件，再生成gltf
                    if (Objects.equals(type, "cad") || Objects.equals(type, "CAD")) {
                        //调用可执行程序mkmesh生成inp文件夹，再调用process_material_inp.py生成gltf文件
                        log.info("材料整备CZ网格划分功能生成inp文件，再生成gltf开始");
                        String result_path = json.getString("result_path");
                        String inp_path = result_path + "/input_cad.inp";
                        FileUtil.isFileFlowExistAndCreate(result_path);

                        //材料整备CZ网格划分功能调用docker可执行程序mkmesh生成inp文件    docker exec -w /root/tsbsDuiJie/mkmesh ubuntu2 ./mkmesh -j data.json
                        log.info("材料整备CZ网格划分功能调用网格划分mkmesh生成inp文件");
                        String exeFilePath = "/root/tsbsDuiJie/mkmesh/mkmesh";
                        String exeDirectory = "/root/tsbsDuiJie/mkmesh";
//                        String[] command = {"docker", "exec", "-w", exeDirectory, containerName, "./mkmesh", "-j", "data.json"};
                        String[] command = {"podman", "exec", "-w", exeDirectory, containerName, "./mkmesh", "-j", "data.json"};
                        res = UseUtil.execDockerMkMeshCommand(command);
                        if (!res.equals("成功")) {
                            res = "可执行程序mkmesh执行失败,inp文件生成失败";
                            task.setProgress(1.0);
                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
                            task.setDone(1);
                            taskMapper.updating(task, task.getId());
                            log.info("返回结果：" + res);
                            return res;
                        }

                        //调用py文件process_material_inp.py，生成gltf文件
                        log.info("材料整备CZ网格划分功能调用process_material_inp.py，inp生成gltf文件");
                        String pyFilePath = "/root/tsbsDuiJie/material/process_material_inp.py";
                        String gltf_path = result_path + "/cz_cad.gltf";
                        //python3 /root/tsbsDuiJie/material/process_material_inp.py /root/tsbsDuiJie/mesh20240401.inp /root/tsbsDuiJie/material/material.gltf
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path};
                        res = UseUtil.exePyCommand(pyCommands);
                        if (res.equals("成功")) {
                            FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/model");//为方便查看，将gltf文件复制到测试路径下
                        }

                    }
                    //CZ-mesh调用可执行程序MeshMerger，生成inp文件，再生成gltf
                    else if (Objects.equals(type, "mesh") || Objects.equals(type, "MESH")) {
                        log.info("材料整备CZ-mesh网格文件生成gltf文件开始");
                        //调用可执行程序MeshMerger，生成inp文件     ./MeshMerger /root/BS/model/2024-03/5/1.mphtxt /root/BS/model/2024-03/5/2.mphtxt  ./test.inp
                        log.info("材料整备CZ-mesh网格文件调用MeshMerger，mphtxt生成inp文件");
                        String exeFilePath = "/root/tsbsDuiJie/MeshMerger/MeshMerger";
                        String directory = "/root/tsbsDuiJie/MeshMerger";
                        String result_path = json.getString("result_path");
                        String inp_path = result_path + "/input_mesh.inp";
//                        JSONArray mesh_path = json.getJSONArray("mesh_path");
                        String meshPath = json.getString("mesh_path");
                        JSONArray mesh_path = new JSONArray();
                        List<String> dataList = new ArrayList<String>();
                        dataList.add(meshPath);
                        mesh_path.addAll(dataList);

                        String[] exeCommands = new String[mesh_path.size() + 2];
                        exeCommands[0] = exeFilePath;
                        for (int i = 0; i < mesh_path.size(); i++) {
                            exeCommands[i + 1] = mesh_path.getString(i);
                        }
                        exeCommands[mesh_path.size() + 1] = inp_path;
                        res = UseUtil.exeProcessCommand(directory, exeCommands);
                        if (!res.equals("成功")) {
                            res = "可执行程序MeshMerger执行失败,inp文件生成失败";
                            task.setProgress(1.0);
                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
                            task.setDone(1);
                            taskMapper.updating(task, task.getId());
                            log.info("返回结果：" + res);
                            return res;
                        }
                        //为方便查看，将inp文件复制到测试路径下
                        FileUtil.copyFile(inp_path, "/root/tsbsDuiJie/model/mesh");

                        //调用py函数inp_to_gltf，用inp生成gltf网格文件
                        log.info("材料整备CZ-mesh网格文件调用inp_to_gltf，inp生成gltf文件");
                        String pyFilePath = "/root/tsbsDuiJie/material/cz_mesh_inp_to_gltf.py";
                        String gltf_path = result_path + "/cz_mesh.gltf";
                        String hist_json_path = result_path + "/hist.json";
                        String count = json.getString("gltf_bar_count");
                        if(ObjectUtils.isEmpty(json.getString("gltf_bar_count")) || Objects.equals(json.getString("gltf_bar_count"), "0") || Objects.equals(json.getString("gltf_bar_count"), "null") ) {
                            hist_json_path = "None";
                            count = "None";
                        }
                        // python3 /root/tsbsDuiJie/material/cz_mesh_inp_to_gltf.py  mesh20240401.inp  test.gltf  False
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        res = UseUtil.exePyCommand(pyCommands);
                        if (res.equals("成功")) {
                            FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/material");//为方便查看，将gltf文件复制到测试路径下
                        }
                    }
                    else if (Objects.equals(type, "MATERIAL") || Objects.equals(type, "material")) {
                        res = "成功";
                    }
                    else {
                        res = "参数type错误，请检查type参数";
                    }
                } catch (Exception e) {
                    log.info("材料整备任务CZ参数异常，parameter参数为" + json + "；请检查cad_path、mesh_path、type、param_type、material_path、maxsize、gltf_bar_count参数情况");
                    res = "材料整备任务CZ参数异常；请检查cad_path、mesh_path、type、param_type、material_path、maxsize、gltf_bar_count参数情况";
                }
            }
            else if (Objects.equals(task.getType(), "MZ") || Objects.equals(task.getType(), "mz")) {
                //模型整备任务MZ
                JSONObject json = JSON.parseObject(task.getParameter());
                try {
                    JSONArray inputFiles = json.getJSONArray("input_files");
                    String mzType = json.getString("type");
                    String model_path = json.getString("model_path"); //存放输出文件
                    FileUtil.isFileFlowExistAndCreate(model_path);

                    if (Objects.equals(mzType, "MESH") || Objects.equals(mzType, "mesh")) {
                        log.info("MZ模型整备MESH调用可执行程序MeshMerger，生成inp文件，再生成gltf文件开始");
                        //调用可执行程序MeshMerger，生成inp文件     ./MeshMerger /root/BS/model/2024-03/5/1.mphtxt /root/BS/model/2024-03/5/2.mphtxt  ./test.inp
                        log.info("MZ模型整备MESH调用可执行程序MeshMerger，mphtxt生成inp文件");
                        String exeFilePath = "/root/tsbsDuiJie/MeshMerger/MeshMerger";
                        String directory = "/root/tsbsDuiJie/MeshMerger";
                        String inp_path = model_path + "/input_files.inp";
                        String[] exeCommands = new String[inputFiles.size() + 2];
                        exeCommands[0] = exeFilePath;
                        for (int i = 0; i < inputFiles.size(); i++) {
                            exeCommands[i + 1] = inputFiles.getString(i);
                        }
                        exeCommands[inputFiles.size() + 1] = inp_path;
                        res = UseUtil.exeProcessCommand(directory, exeCommands);
                        if (!res.equals("成功")) {
                            res = "可执行程序MeshMerger执行失败,inp文件生成失败";
                            task.setProgress(1.0);
                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
                            task.setDone(1);
                            taskMapper.updating(task, task.getId());
                            log.info("返回结果：" + res);
                            return res;
                        }
                        //为方便查看，将inp文件复制到测试路径下
                        FileUtil.copyFile(inp_path, "/root/tsbsDuiJie/model/mesh");

                        //调用py文件mz_inp_to_gltf，用inp生成gltf网格文件
                        log.info("MZ模型整备MESH调用py文件mz_inp_to_gltf，inp生成gltf文件");
                        // python3 /root/tsbsDuiJie/model/mesh/mz_mesh_inp_to_gltf.py  /root/tsbsDuiJie/model/mesh/input_files.inp  /root/tsbsDuiJie/model/mesh/mesh.gltf False
                        String pyFilePath = "/root/tsbsDuiJie/model/mesh/mz_mesh_inp_to_gltf.py";
                        String gltf_path = model_path + "/mesh.gltf";
                        String hist_json_path = model_path + "/hist.json";
                        String count = json.getString("gltf_bar_count");
                        if(ObjectUtils.isEmpty(json.getString("gltf_bar_count")) || Objects.equals(json.getString("gltf_bar_count"), "0") || Objects.equals(json.getString("gltf_bar_count"), "null") ) {
                            hist_json_path = "None";
                            count = "None";
                        }
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, hist_json_path, count, "False"};
                        res = UseUtil.exePyCommand(pyCommands);
                        if (res.equals("成功")) {
                            FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/model/mesh");//为方便查看，将gltf文件复制到测试路径下
                        }
                    }
                    else if (Objects.equals(mzType, "CAD") || Objects.equals(mzType, "cad")) {
                        log.info("MZ模型整备CAD网格划分mkmesh功能生成inp文件，再生成gltf开始");
                        String inp_path = model_path + "/input_cad.inp";
                        FileUtil.isFileFlowExistAndCreate(model_path);

                        //模型整备CAD网格划分功能生成inp文件   docker exec -w /root/tsbsDuiJie/mkmesh ubuntu2 ./mkmesh -j data.json
                        log.info("MZ模型整备CAD网格划分功能mkmesh，stp生成inp文件");
                        String exeFilePath = "/root/tsbsDuiJie/mkmesh/mkmesh";
                        String directory = "/root/tsbsDuiJie/mkmesh";
//                        String[] command = {"docker", "exec", "-w", directory, containerName, "./mkmesh", "-j", "data.json"};
                        String[] command = {"podman", "exec", "-w", directory, containerName, "./mkmesh", "-j", "data.json"};
                        res = UseUtil.execDockerMkMeshCommand(command);
                        if (!res.equals("成功")) {
                            res = "可执行程序mkmesh执行失败,inp文件生成失败";
                            task.setProgress(1.0);
                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
                            task.setDone(1);
                            taskMapper.updating(task, task.getId());
                            log.info("返回结果：" + res);
                            return res;
                        }

                        //调用py文件process_par_cad_inp.py，生成gltf网格文件和part.json文件
                        log.info("MZ模型整备CAD网格划分功能调用py文件process_par_cad_inp.py，inp生成gltf文件");
                        //python3 /root/tsbsDuiJie/model/process_par_cad_inp.py /root/tsbsDuiJie/mesh20240401.inp /root/tsbsDuiJie/model/type.gltf /root/tsbsDuiJie/model/part.json /root/tsbsDuiJie/model/hist.json 100
                        String pyFilePath = "/root/tsbsDuiJie/model/process_par_cad_inp.py";
                        String gltf_path = model_path + "/" + mzType + ".gltf";
                        String json_path = model_path + "/part.json";
                        String hist_json_path = model_path + "/hist.json";
                        String count = json.getString("gltf_bar_count");
                        if(ObjectUtils.isEmpty(json.getString("gltf_bar_count")) || Objects.equals(json.getString("gltf_bar_count"), "0") || Objects.equals(json.getString("gltf_bar_count"), "null") ) {
                            hist_json_path = "None";
                            count = "None";
                        }
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};

                        res = UseUtil.exePyCommand(pyCommands);
                        if(res.equals("成功")) {
                            FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/model/cad");//为方便查看，将gltf文件复制到测试路径下
                            FileUtil.copyFile(json_path, "/root/tsbsDuiJie/model/cad");//为方便查看，将part.json文件复制到测试路径下
                        }
                    }
                    else if (Objects.equals(mzType, "PAR") || Objects.equals(mzType, "par")) {
                        log.info("MZ模型整备PAR参数化建模生成stp文件，然后网格划分mkmesh功能生成inp文件，再生成gltf开始");
                        String inpName = "input_par.inp";
                        String inp_path = model_path + "/" + inpName;
                        FileUtil.isFileFlowExistAndCreate(model_path);

                        //MZ模型整备PAR参数化建模genGeoModel生成stp文件    docker exec -w /root/tsbsDuiJie/genGeoModel ubuntu2 ./genGeoModel data.json
                        log.info("MZ模型整备PAR参数化建模genGeoModel，参数转data.json生成stp文件");
                        String genGeoModelMkdir = "/root/tsbsDuiJie/genGeoModel";  //可执行文件所在目录
//                        String[] command = {"docker", "exec", "-w", genGeoModelMkdir, containerName, "./genGeoModel", "data.json"};
                        String[] command = {"podman", "exec", "-w", genGeoModelMkdir, containerName, "./genGeoModel", "data.json"};
                        res = UseUtil.execDockerCommand(command);
                        if (!Objects.equals(res, "成功")) {
                            endTask.setResponse("{\"log\":" + "\"" + res + "\"}");
                            taskMapper.updating(endTask, endTask.getId());
                            return "docker容器igs和stp文件生成失败";
                        }

//                        String stpName = "test.stp";
//                        String igsName = "test.igs";
//                        String sourceIgsPath = genGeoModelMkdir +"/"+ igsName;
//                        String sourceStpPath = genGeoModelMkdir + "/" + stpName;
                        JSONObject params = JSON.parseObject(json.getString("params"));
                        String stpName = params.getString("stp_file");
                        String igsName = params.getString("igs_file");
                        String sourceIgsPath = igsName;
                        if(FileUtil.getMkdirPath(sourceIgsPath).equals("")) {
                            sourceIgsPath = genGeoModelMkdir + "/" + igsName;
                        }
                        String sourceStpPath = stpName;
                        if(FileUtil.getMkdirPath(sourceStpPath).equals("")) {
                            sourceStpPath = genGeoModelMkdir + "/" + stpName;
                        }
                        //复制容器中的igs文件到model_path
                        res = FileUtil.copyFile(sourceIgsPath, model_path);
                        if (!Objects.equals(res, "成功")) {
                            endTask.setResponse("{\"log\":" + "\"" + res + "\"}");
                            taskMapper.updating(endTask, endTask.getId());
                            return "docker中igs文件传输失败";
                        }
                        FileUtil.copyFile(sourceIgsPath, "/root/tsbsDuiJie/model/par");//为方便查看，将igs文件复制到测试路径下

                        //复制容器中的stp文件到测试路径
                        res = FileUtil.copyFile(sourceStpPath, model_path);
                        if (!Objects.equals(res, "成功")) {
                            endTask.setResponse("{\"log\":" + "\"" + res + "\"}");
                            taskMapper.updating(endTask, endTask.getId());
                            return "docker中stp文件传输失败";
                        }
                        FileUtil.copyFile(sourceStpPath, "/root/tsbsDuiJie/model/par");//为方便查看，将stp文件复制到测试路径下

                        //更改mkmesh的data.json
                        log.info("开始更改mkmesh的data.json文件");
                        String type = "doSurfaceMesh";
                        String[] input_files_array = new String[1];
                        input_files_array[0] = sourceStpPath;
                        if(ObjectUtils.isEmpty(json.getFloat("maxsize")) || ObjectUtils.isEmpty(model_path) ) {
                            return "MZ模型整备PAR参数异常！请检查maxsize、model_path参数情况！"+json;
                        }
                        float maxsize = json.getFloat("maxsize");
                        //log.info("maxsize:"+maxsize);
                        MZ data = new MZ();
                        data.setType(type);
                        data.setInput_files(input_files_array);
                        data.setModel_path(inp_path);
                        data.setMaxsize(maxsize);
                        //log.info("./mkmesh/data.json:"+JSON.toJSONString(data));
                        boolean flag = FileUtil.creatJsonFile(JSON.toJSONString(data), "/root/tsbsDuiJie/mkmesh/data.json");
                        if(flag == false) {
                            return "MZ模型整备PAR参数异常！网格划分mkmesh的data.json文件生成失败！";
                        }
                        log.info("更改mkmesh的data.json文件成功" + flag);


                        //模型整备PAR生成网格划分功能mkmesh需要的json文件
                        log.info("开始mkmesh调用data.json生成inp");
                        UseUtil.createMkMeshJsonFile(task.getParameter(),sourceStpPath,inp_path);
                        //模型整备PAR网格划分功能生成inp文件   docker exec -w /root/tsbsDuiJie/mkmesh ubuntu2 ./mkmesh -j data.json
                        String directory = "/root/tsbsDuiJie/mkmesh";
//                        String[] commands = {"docker", "exec", "-w", directory, containerName, "./mkmesh", "-j", "data.json"};
                        String[] commands = {"podman", "exec", "-w", directory, containerName, "./mkmesh", "-j", "data.json"};
                        res = UseUtil.execDockerMkMeshCommand(commands);
                        if (!res.equals("成功")) {
                            res = "可执行程序mkmesh执行失败,inp文件生成失败";
                            task.setProgress(1.0);
                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
                            task.setDone(1);
                            taskMapper.updating(task, task.getId());
                            log.info("返回结果：" + res);
                            return res;
                        }
                        //复制容器中的inp文件到model_path
//                        String sourceInpPath = directory +"/"+ "mkmesh.inp";
//                        res = FileUtil.copyFile(sourceInpPath, model_path);
//                        if (!Objects.equals(res, "成功")) {
//                            endTask.setResponse("{\"log\":" + "\"" + res + "\"}");
//                            taskMapper.updating(endTask, endTask.getId());
//                            return "docker中inp文件传输失败";
//                        }


                        log.info("模型整备PAR调用py文件process_par_cad_inp.py，inp生成gltf、part.json、hist.json");
                        //模型整备PAR调用py文件process_par_cad_inp.py，生成gltf网格文件和part.json文件
                        //python3 /root/tsbsDuiJie/model/par/process_par_cad_inp.py /root/tsbsDuiJie/mesh20240401.inp /root/tsbsDuiJie/model/type.gltf /root/tsbsDuiJie/model/part.json
                        String pyFilePath = "/root/tsbsDuiJie/model/process_par_cad_inp.py";
                        String gltf_path = model_path + "/" + mzType + ".gltf";
                        String json_path = model_path + "/part.json";
                        String hist_json_path = model_path + "/hist.json";
                        String count = json.getString("gltf_bar_count");
                        if(ObjectUtils.isEmpty(json.getString("gltf_bar_count")) || Objects.equals(json.getString("gltf_bar_count"), "0") || Objects.equals(json.getString("gltf_bar_count"), "null") ) {
                            hist_json_path = "None";
                            count = "None";
                        }
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path, json_path, hist_json_path, count};

                        res = UseUtil.exePyCommand(pyCommands);
                        FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/model/par");//为方便查看，将gltf文件复制到测试路径下
                        FileUtil.copyFile(json_path, "/root/tsbsDuiJie/model/par");//为方便查看，将part.json文件复制到测试路径下
                    }
                    else {
                        res = "参数type错误，请检查type参数";
                    }
                } catch (Exception e) {
                    log.info("模型整备任务MZ-PAR参数异常，parameter参数为" + json + "；请检查type、model_path、params、maxsize参数情况");
                    res = "模型整备任务MZ-PAR参数异常；请检查type、model_path、params、maxsize参数情况";
                }
            }
//            else if (Objects.equals(task.getType(), "MH") || Objects.equals(task.getType(), "mh")) {
//                //MH网格划分用户传入cad文件生成inp文件，再生成gltf   ***data.json文件还未生成
//                JSONObject json = JSON.parseObject(task.getParameter());
//                try {
//                        //调用docker可执行程序mkmesh生成inp文件夹，再调用inp_to_gltf.py生成gltf文件
//                        log.info("MH网格划分功能生成inp文件，再生成gltf开始");
//                        String result_path = json.getString("result_path");
//                        String inp_path = result_path + "/input_mh.inp";
//                        FileUtil.isFileFlowExistAndCreate(result_path);
//
//                        //材料整备CZ网格划分功能调用docker可执行程序mkmesh生成inp文件夹    docker exec -w /root/tsbsDuiJie/mkmesh ubuntu2 ./mkmesh -j data.json
//                        String exeFilePath = "/root/tsbsDuiJie/mkmesh/mkmesh";
//                        String directory = "/root/tsbsDuiJie/mkmesh";
//                        String[] command = {"docker", "exec", "-w", directory, containerName, "./mkmesh", "-j", "data.json"};
//                        res = UseUtil.execDockerMkMeshCommand(command);
//                        if (!res.equals("成功")) {
//                            res = "可执行程序mkmesh执行失败,inp文件生成失败";
//                            task.setProgress(1.0);
//                            task.setResponse("{\"log\":" + "\"" + res + "\"}");
//                            task.setDone(1);
//                            taskMapper.updating(task, task.getId());
//                            log.info("返回结果：" + res);
//                            return res;
//                        }
//
//                        //调用py文件process_material_inp.py，生成gltf文件
//                        //python3 /root/tsbsDuiJie/material/process_material_inp.py /root/tsbsDuiJie/mesh20240401.inp /root/tsbsDuiJie/material/material.gltf
//                        String pyFilePath = "/root/tsbsDuiJie/mh/process_mh_inp.py";
//                        String gltf_path = result_path + "/guapi.gltf";
//                        String[] pyCommands = {"python3", pyFilePath, inp_path, gltf_path};
//                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, inp_path, gltf_path};
//                        res = UseUtil.exePyCommand(pyCommands);
//                        if (res.equals("成功")) {
//                            FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/mh");//为方便查看，将gltf文件复制到测试路径下
//                        }
//                } catch (Exception e) {
//                    log.info("MH网格划分参数异常，parameter参数为" + json + "；请检查cad_path、params（可选）、mesh_size、result_path参数情况");
//                    res = "MH网格划分参数异常；请检查cad_path、params（可选）、mesh_size、result_path参数情况";
//                }
//            }
            //生成gltf更新任务进度0.15
            if (!res.equals("成功")) {
                task.setProgress(1.0);
                task.setResponse("{\"log\":" + "\"" + res + "\"}");
                task.setDone(1);
                taskMapper.updating(task, task.getId());
                log.info("返回结果：" + res);
                return res;
            } else {
                task.setProgress(0.15);
                taskMapper.updating(task, task.getId());
            }


            //生成dat文件     后续需更改  JP生成.dat和gltf文件
            log.info(task.getType()+"准备生成dat文件");
            if (Objects.equals(task.getType(), "BP") || Objects.equals(task.getType(), "bp")) {
                log.info("生成频域计算相关文件");
                log.info("创建一个固定大小为4的线程池");
                // 创建一个固定大小的线程池
                double poolSize = 4.0;
                String[] message = new String[(int) poolSize];
                ExecutorService executor = Executors.newFixedThreadPool((int) poolSize);
                final double[] success = {0.0};
                for (int i = 0; i < poolSize; i++) {
                    log.info("线程加入任务");
//            TestThread thread = new TestThread(i, length, task.getType(), task.getParameter(), message[i], task);
//            executor.execute(thread);
                    int fin = i;
                    executor.execute(new Runnable() {
                        @SneakyThrows
                        public void run() {
                            int finalI = fin;
                            log.info("线程池第" + finalI + "个线程开始执行!,下标为" + finalI);
                            message[finalI] = runStorage(task, (int) poolSize, finalI);

                            //更新任务进度
                            task.setProgress(success[0] += 1.0 / poolSize - 0.05);
                            taskMapper.updating(task, task.getId());
                        }
                    });
                }
                // 关闭线程池
                executor.shutdown();
                log.info("关闭线程池!");
                // 等待线程池执行完毕
                log.info("等待频域线程池执行完毕!");

                while (!executor.isTerminated()) {
                    Thread.sleep(1000);
//                System.out.println("还没停止。。。");
                }

                log.info("频域线程全部完成!");
                if (Objects.equals(message[0], "成功") && Objects.equals(message[1], "成功") && Objects.equals(message[2], "成功")
                        && Objects.equals(message[3], "成功")) {
                    //拼接频域可执行文件生成的结果文件
                    JSONObject json = JSON.parseObject(task.getParameter());
                    String result_path = json.getString("result_path");
                    FileUtil.isFileFlowExistAndCreate(result_path);
                    //将拼接的结果文件复制到目标文件夹
                    res = UseUtil.concatAndCopyDatFile(task.getType(), result_path);
                } else {
                    if (!Objects.equals(message[0], "成功")) {
                        res = message[0];
                    } else if (!Objects.equals(message[1], "成功")) {
                        res = message[1];
                    } else if (!Objects.equals(message[2], "成功")) {
                        res = message[2];
                    } else if (!Objects.equals(message[3], "成功")) {
                        res = message[3];
                    }
                }
                //更新频域任务进度
                task.setProgress(0.9);
                task.setResponse("{\"log\":" + "\"" + res + "\"}");
                task.setDone(1);
                taskMapper.updating(task, task.getId());
            }
            else if (Objects.equals(task.getType(), "BS") || Objects.equals(task.getType(), "bs")) {
                log.info("时域计算相关文件");
                log.info("创建一个固定大小为4的线程池");
                // 创建一个固定大小的线程池
                double poolSize = 4.0;
                String[] message = new String[(int) poolSize];
                ExecutorService executor = Executors.newFixedThreadPool((int) poolSize);
                final double[] success = {0.0};
                for (int i = 0; i < poolSize; i++) {
                    log.info("线程加入任务");
//            TestThread thread = new TestThread(i, length, task.getType(), task.getParameter(), message[i], task);
//            executor.execute(thread);
                    int fin = i;
                    executor.execute(new Runnable() {
                        @SneakyThrows
                        public void run() {
                            int finalI = fin;
                            log.info("线程池第" + finalI + "个线程开始执行!,下标为" + finalI);
                            message[finalI] = runStorage(task, (int) poolSize, finalI);

                            //更新任务进度
                            task.setProgress(success[0] += 1.0 / poolSize - 0.05);
                            taskMapper.updating(task, task.getId());
                        }
                    });
                }
                // 关闭线程池
                executor.shutdown();
                log.info("关闭线程池!");
                // 等待线程池执行完毕
                log.info("等待时域线程池执行完毕!");
                while (!executor.isTerminated()) {
                    Thread.sleep(1000);
//                System.out.println("还没停止。。。");
                }

                log.info("时域线程全部完成!");
                if (Objects.equals(message[0], "成功") && Objects.equals(message[1], "成功") && Objects.equals(message[2], "成功")
                        && Objects.equals(message[3], "成功")) {
                    //拼接时域可执行文件生成的结果文件
                    JSONObject json = JSON.parseObject(task.getParameter());
                    String result_path = json.getString("path");
                    FileUtil.isFileFlowExistAndCreate(result_path);
                    //将拼接的结果文件复制到目标文件夹
                    res = UseUtil.concatAndCopyDatFile(task.getType(), result_path);
                } else {
                    if (!Objects.equals(message[0], "成功")) {
                        res = message[0];
                    } else if (!Objects.equals(message[1], "成功")) {
                        res = message[1];
                    } else if (!Objects.equals(message[2], "成功")) {
                        res = message[2];
                    } else if (!Objects.equals(message[3], "成功")) {
                        res = message[3];
                    }
                }
                //更新时域任务进度
                task.setProgress(0.9);
                task.setResponse("{\"log\":" + "\"" + res + "\"}");
                task.setDone(1);
                taskMapper.updating(task, task.getId());
            }
            else if (Objects.equals(task.getType(), "JP") || Objects.equals(task.getType(), "jp")) {
                log.info("解析解JP生成gltf和dat文件开始");
                //解析解频域任务JP
                JSONObject json = JSON.parseObject(task.getParameter());
                try {
                    String params = json.getString("params");
                    String hor = json.getString("hor");
                    String ver = json.getString("ver");
                    String freq = json.getString("freq");
                    String radius = json.getString("radius");
                    String path = json.getString("path");
                    FileUtil.isFileFlowExistAndCreate(path);

                    //params存储在data.json
                    params = FileUtil.readFileToString("/root/tsbsDuiJie/analyze/data.json");

                    //调用py文件models.py，生成gltf文件和dat文件
                    log.info("调用python文件models.py，param参数转data.json及其他参数生成gltf文件和dat文件");
                    //python3 /root/tsbsDuiJie/analyze/models.py /root/tsbsDuiJie/analyze/data.json [0, 360, 2] [60, 120, 2] [10, 1000, 10] /root/tsbsDuiJie/guapi.gltf /root/tsbsDuiJie/result.dat
                    String pyFilePath = "/root/tsbsDuiJie/analyze/models.py";
                    String dat_path = path + "/result.dat";
                    String gltf_path = path + "/guapi.gltf";
//                    String[] pyCommands = {"python3", pyFilePath, params, hor, ver, freq, dat_path, gltf_path};
                    String directoryPython = "/root/tsbsDuiJie";
//                    String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, params, hor, ver, freq, dat_path, gltf_path};
                    String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, params, hor, ver, freq, dat_path, gltf_path};
                    res = UseUtil.exePyCommand(pyCommands);
                    FileUtil.copyFile(gltf_path, "/root/tsbsDuiJie/analyze");//为方便查看，将gltf文件复制到测试路径下
                    FileUtil.copyFile(dat_path, "/root/tsbsDuiJie/analyze");//为方便查看，将dat文件复制到测试路径下
                } catch (Exception e) {
                    log.info("解析解频域任务JP参数异常，parameter参数为" + json + "；请检查hor、ver、freq、radius、path参数情况");
                    res = "解析解频域任务JP参数异常，生成gltf和dat文件失败";
                }
            }
            else if (Objects.equals(task.getType(), "CZ") || Objects.equals(task.getType(), "cz")) {
                log.info("材料整备任务CZ,material生成csv和dat文件开始");
                //材料整备任务CZ
                JSONObject json = JSON.parseObject(task.getParameter());

                try {
                    String type = json.getString("type");
                    if (Objects.equals(type, "material") || Objects.equals(type, "MATERIAL")) {
                        log.info("材料整备任务CZ-material，调用process_test_material.py，csv生成展示csv和dat文件开始");
                        //调用py文件 process_test_material.py，生成dat文件和展示csv文件 single angle、 multi angle
                        //python  py文件路径  用户导入的csv文件 r.dat、t.dat所放置的文件夹  任务类型（'r'反射，'t'透射） 前端显示的实值csv文件路径  板块元计算的材料系数dat文件路径
                        //python3 ./material/process_test_material.py /root/tsbsDuiJie/material/多角度反投射系数模板.csv /root/tsbsDuiJie/material/dat r /root/tsbsDuiJie/dis_csv.csv /root/tsbsDuiJie/dis_res.dat
                        String pyFilePath = "/root/tsbsDuiJie/material/process_test_material.py";
                        String csv_path = json.getString("material_path");
                        String template_dir = "/root/tsbsDuiJie/material/dat";
                        String param_type = json.getString("param_type");
                        String result_path = json.getString("result_path");
                        FileUtil.isFileFlowExistAndCreate(result_path);
                        String display_csv_fn = result_path + "/" + param_type + "_display.csv";
                        String cal_dat_fn = result_path + "/" + param_type + "_result.dat";

//                        String[] pyCommands = {"python3", pyFilePath, csv_path, template_dir, param_type, display_csv_fn, cal_dat_fn};
                        String directoryPython = "/root/tsbsDuiJie";
//                        String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, csv_path, template_dir, param_type, display_csv_fn, cal_dat_fn};
                        String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, csv_path, template_dir, param_type, display_csv_fn, cal_dat_fn};
                        res = UseUtil.exePyCommand(pyCommands);
                        if (res.equals("成功")) {
                            FileUtil.copyFile(display_csv_fn, "/root/tsbsDuiJie/material");//为方便查看，将csv文件复制到测试路径下
                            FileUtil.copyFile(cal_dat_fn, "/root/tsbsDuiJie/material");//为方便查看，将dat文件复制到测试路径下
                        }
                    }
                    else if (Objects.equals(type, "cad") || Objects.equals(type, "CAD")) {
                        res = "成功";
                    }
                    else if(Objects.equals(type, "mesh") || Objects.equals(type, "MESH")) {
                        res = "成功";
                    }
                    else {
                        log.info("材料整备任务CZ参数异常，parameter参数为" + json + "；请检查type参数情况");
                        res = "材料整备任务CZ参数异常，生成csv和dat文件失败";
                    }
                } catch (Exception e) {
                    log.info("材料整备任务CZ参数异常，parameter参数为" + json + "；请检查result_path、type、param_type、material_path参数情况");
                    res = "材料整备任务CZ参数异常，生成csv和dat文件失败";
                }
            }
            else if (Objects.equals(task.getType(), "XB") || Objects.equals(task.getType(), "xb")) {
                log.info("XB效能分析-被动生成dat文件开始");
                //XB效能分析-被动
                JSONObject json = JSON.parseObject(task.getParameter());
                String path = json.getString("path");
                FileUtil.isFileFlowExistAndCreate(path);

                try {
                    //调用py文件 passive.py，生成dat文件
                    //python  ./passive/passive.py passive材料所在文件目录  Parameter参数
                    //python3 ./passive/passive.py /root/tsbsDuiJie/passive/passive-test Parameter参数
                    String pyFilePath = "/root/tsbsDuiJie/passive/passive.py";
                    String passiveMkdir = "/root/tsbsDuiJie/passive/passive-test";

//                    JSONObject red = JSON.parseObject(json.getString("red"));
//                    red.put("spectrum_path", passiveMkdir+"/F_signal.csv");
//                    json.put("red", red);
//                    String parame = "\'" + json.toJSONString() + "\'";
                    String parame = json.toJSONString();

//                    String[] pyCommands = {"python3", pyFilePath, passiveMkdir, parame};
                    String directoryPython = "/root/tsbsDuiJie";
//                    String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, passiveMkdir, parame};
                    String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, parame};
                    res = UseUtil.exePyCommand(pyCommands);
                    if(!res.equals("成功")) {
                        log.info(res);
                    }

                } catch (Exception e) {
                    log.info("XB效能分析-被动参数异常，parameter参数为" + json + "；请检查parameter参数情况");
                    res = "XB效能分析-被动参数异常，生成csv和dat文件失败；请检查parameter参数情况";
                }
            }
            else if (Objects.equals(task.getType(), "XZ") || Objects.equals(task.getType(), "xz")) {
                log.info("XZ效能分析-主动生成dat文件开始");
                //XB效能分析-被动
                JSONObject json = JSON.parseObject(task.getParameter());
                String path = json.getString("path");
                FileUtil.isFileFlowExistAndCreate(path);

                try {
                    //调用py文件 passive.py，生成dat文件
                    //python  ./passive/passive.py passive材料所在文件目录  Parameter参数
                    //python3 ./passive/passive.py /root/tsbsDuiJie/passive/passive-test Parameter参数
                    String pyFilePath = "/root/tsbsDuiJie/xz/active.py";
                    String passiveMkdir = "/root/tsbsDuiJie/xz/passive-test";

                    JSONObject save = new JSONObject();
                    save.put("path", path);
                    json.put("save", save);
//                    json.remove("path");
                    String parame = json.toJSONString();
//                    String parame = "'" + json.toJSONString() + "'";

//                    String[] pyCommands = {"python3", pyFilePath, passiveMkdir, parame};
                    //python3 ./passive/passive.py /root/tsbsDuiJie/passive/passive-test '{"path": "/root/tsbsDuiJie", "array": {"type": 2, "r": [1, 10, 0.1], "theta_div": 5, "depth": [100, 500, 5]}, "red": {"model_id": 1, "longitude": 108.22, "latitude": 28.12, "depth": 150.0, "orientation": 90.0, "spectrum_path": "/root/tsbsDuiJie/passive/passive-test/F_signal.csv", "directional_path": "指向性数据 csv 文件路径"}}'
                    String directoryPython = "/root/tsbsDuiJie";
//                    String[] pyCommands = {"docker", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, passiveMkdir, parame};
                    String[] pyCommands = {"podman", "exec", "-w", directoryPython, containerName, "python3", pyFilePath, parame};
                    res = UseUtil.exePyCommand(pyCommands);
                    if(!res.equals("成功")) {
                        log.info("XZ效能分析-主动生成文件失败；请检查parameter参数情况"+json);
                        log.info(res);
                    }

                } catch (Exception e) {
                    log.info("XZ效能分析-主动参数异常，parameter参数为" + json + "；请检查parameter参数情况");
                    res = "XZ效能分析-主动参数异常，生成csv和dat文件失败；请检查parameter参数情况";
                }
            }
            //生成dat更新任务进度0.9
            if (!res.equals("成功")) {
                task.setProgress(1.0);
                task.setResponse("{\"log\":" + "\"" + res + "\"}");
                task.setDone(1);
                taskMapper.updating(task, task.getId());
                log.info("返回结果：" + res);
                return res;
            } else {
                task.setProgress(0.9);
                taskMapper.updating(task, task.getId());
            }

            if (!Objects.equals(checkTaskType(task.getType()), "成功")) {
                res = "任务类型为" + task.getType() + "，不处理";
            }
            //对应任务全部完成，更新任务进度
            task.setProgress(1.0);
            task.setResponse("{\"log\":" + "\"" + res + "\"}");
            task.setDone(1);
            taskMapper.updating(task, task.getId());
            log.info("返回结果：" + res);
            return res;


//        } catch (Exception e) {
//            log.info("任务执行中断，信息："+e.getMessage());
//            log.info(e.getMessage());
//            task.setProgress(1.0);
//            task.setResponse("{\"log\":" + "\"" + e.getMessage() + "\"}");
//            task.setDone(1);
//            taskMapper.updating(task, task.getId());
//            return e.getMessage();
//        }
    }

    @Override
    public Task getById(Integer id){
        return taskMapper.getById(id);
    }

    @Override
    public int updating(Task data, Integer id) {
        taskMapper.updating(data, id);
        return 1;
    }

    public String checkTaskType(String taskType) {
        String res = "";
        String[] type = {"MZ", "CZ", "BP", "BS", "JP", "XB", "mz", "cz", "bp", "bs", "jp", "xb"};
        for (String i : type) {
            if(i.equals(taskType)) {
                res = "成功";
            }
        }
        return res;
    }

    public String runStorage(Task task, Integer poolSize, Integer index) throws IOException {
        String taskType = task.getType();
        String parameter = task.getParameter();
        String containerName = "ubuntu2";
        String result = "";
        if (Objects.equals(taskType, "BP") || Objects.equals(taskType, "bp")) {
            //板块元频域任务BP
            JSONObject json = JSON.parseObject(parameter);

            String calFileName = "/root/tsbsDuiJie/ts/freq_cal";//频域可执行文件freq_cal的路径
//            String jsonFileName = "/root/tsbsDuiJie/ts/freq.json";//可执行文件调用的json文件路径
            String jsonFileName = "/root/tsbsDuiJie/ts/"+task.getId()+"/freq.json";//可执行文件调用的json文件路径
            if(!FileUtil.isFileExist(calFileName) ||  !FileUtil.isFileExist(jsonFileName)) {
                return calFileName+"或"+jsonFileName+"文件不存在";
            }
            String directory = "/root/tsbsDuiJie/ts";

            //调用频域可执行程序程序,获取.dat文件，此时结果文件在程序同一目录下
            log.info("调用BP可执行文件"+calFileName);
//            String result1 = UseUtil.callExe(calFileName, jsonFileName, directory, poolSize, index);
//            String[] commands = {"docker", "exec", "-w", directory, containerName, calFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String[] commands = {"podman", "exec", "-w", directory, containerName, calFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String result1 = UseUtil.execBSAndBPDockerCommand(commands);

            if(!Objects.equals(result1, "成功")) {
                return result1;
            }
            result = "成功";

        }
        else if (Objects.equals(taskType, "BS") || Objects.equals(taskType, "bs")) {
            //板块元时域任务BS
            JSONObject json = JSON.parseObject(parameter);

            String calTimeFileName = "/root/tsbsDuiJie/time_light/time_cal";//频域可执行文件time_cal的路径
            String calLightFileName = "/root/tsbsDuiJie/time_light/light_cal";//频域可执行文件light_cal的路径
//            String jsonFileName = "/root/tsbsDuiJie/time_light/time_light.json";//可执行文件调用的json文件路径
            String jsonFileName = "/root/tsbsDuiJie/time_light/"+task.getId()+"/time_light.json";//可执行文件调用的json文件路径
            if(!FileUtil.isFileExist(calLightFileName) || !FileUtil.isFileExist(calLightFileName) || !FileUtil.isFileExist(jsonFileName)) {
                return calTimeFileName+"或"+calLightFileName+"或"+jsonFileName+"文件不存在";
            }
            String directory = "/root/tsbsDuiJie/time_light";

            //调用时域time可执行程序程序,获取.dat文件，此时结果文件在程序同一目录下
//            String result1 = UseUtil.callExe(calTimeFileName, jsonFileName, directory, poolSize, index);
//            String[] commands = {"docker", "exec", "-w", directory, containerName, calTimeFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String[] commands = {"podman", "exec", "-w", directory, containerName, calTimeFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String result1 = UseUtil.execBSAndBPDockerCommand(commands);

            if(!Objects.equals(result1, "成功")) {
                return result1;
            }
            //调用时域light可执行程序程序,获取.dat文件，此时结果文件在程序同一目录下
//            String result2 = UseUtil.callExe(calLightFileName, jsonFileName, directory, poolSize, index);
//            String[] command = {"docker", "exec", "-w", directory, containerName, calLightFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String[] command = {"podman", "exec", "-w", directory, containerName, calLightFileName, jsonFileName, String.valueOf(poolSize), String.valueOf(index)};
            String result2 = UseUtil.execBSAndBPDockerCommand(command);

            if(!Objects.equals(result2, "成功")) {
                return result2;
            }
            result = "成功";
        }
        else {
            //log.info("任务类型为"+taskType+",暂无法进行计算");
            result = "任务类型为"+taskType+"暂无法进行计算";
        }
        return result;
    }


//    @Override
//    public PageInfo<TaskVO> getList(int pageNumber, int pageSize, String schemeName, String modelPartName, String modelName, String modelType,
//                                    String beginTime, String endTime, String formatComment, Integer formated) {
//        PageHelper.startPage(pageNumber, pageSize);
//        return new PageInfo<>(taskMapper.getList(schemeName, modelPartName, modelName, modelType, beginTime, endTime, formatComment, formated));
//    }
//
//    @Override
//    public int add(Task data) {
//        String name = data.getName();
//        if (ObjectUtils.isNotEmpty(taskMapper.getOneByName(name))) {
//            return -1;
//        } else {
//            taskMapper.add(data);
//            return 1;
//        }
//    }
//

//
//    @Override
//    public void deleting(Integer id) {
//        taskMapper.deleting(id);
//        //更改计算表 `Task`中对应方案主键为null
//
//        //删除对应文件夹
//    }



}




